<template>
    <div class="main">
    <van-nav-bar
  title="标题"
  left-text="返回"
  @click-left="onClickLeft"
  class="van1"
/>
    <van-form @submit="onSubmit">
  <van-field
    v-model="username"
    name="用户名"
    label="用户名"
    placeholder="用户名"
    :rules="[{ required: true, message: '请填写用户名' }]"
  />
  <van-field
    v-model="password"
    type="password"
    name="密码"
    label="密码"
    placeholder="密码"
    :rules="[{ required: true, message: '请填写密码' }]"
  />
  <van-field
    v-model="userage"
    name="年龄"
    label="年龄"
    placeholder="年龄"
    :rules="[{ required: true, message: '请输入年龄' }]"
  />
  
  <van-radio-group v-model="radio" direction="horizontal" class="van-radio" @change="change">
  <span>性别：</span>
  <van-radio :name="index" v-for="(v,index) in sexs" :key="index" :value="v" :v-model="v" >{{v}}</van-radio>
</van-radio-group>
  <div style="margin: 16px;">
    <van-button round block type="info" native-type="submit" @click="sub()">提交</van-button>
  </div>
</van-form>
    </div>
</template>
<script>
import url from "../tools/url"
import { Indicator } from 'mint-ui';
import Vue from 'vue';
import { Toast } from 'vant';
Vue.use(Toast);
export default {
    name:"change_info",
    data() {
        return {
          id:"",
          username:"",
          password:"",
          userage:"",
          phone:"",
          radio:"",
          sexs:["女","男"],
          sexnum:""
        }
    },
    methods: {
      change(v){
       if(v==0){
         this.sexnum=2;
       }else{
         this.sexnum=1;
       }


      },
     
     onClickLeft(){
       this.$router.go(-1);
     },
     onSubmit(){

     },
     sub(){
       Indicator.open();
       var str=`id=${this.id}&token=${sessionStorage.getItem("token")}&password=${this.password}&age=${this.userage}&name=${this.username}&gender=${this.sexnum}`
        this.axios.post(url.UPDATECHECKBYID,str).then(pro=>{
          if(pro.data.code==200){
          pro.data.name=this.username;
          pro.data.password=this.password;
          pro.data.age=this.userage;
          pro.data.gender=this.sexnum;
          Indicator.close();
          Toast("修改成功")
          sessionStorage.setItem("user",JSON.stringify(pro.data.data))
          }
        })
        
        
     }
    },
    mounted() {
      this.id=this.$route.query.id;
    },
    destroyed() {
        
    },
}
</script>
<style scoped>
.main{
    text-align: center;
}
.van1{
  background-color: rosybrown;
}
.van-radio{
  margin-left: 4%;
}
</style>